package com.liu.jbase.service.db.impl;

import java.io.Serializable;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;

import com.github.miemiedev.mybatis.paginator.domain.PageBounds;
import com.github.miemiedev.mybatis.paginator.domain.PageList;
import com.liu.jbase.PageListVo;
import com.liu.jbase.dao.IBaseDao;
import com.liu.jbase.service.db.IDBBaseService;

public class DBBaseServiceImpl<R, T, E extends IBaseDao<R, T>> implements IDBBaseService<R, T>{

	@Autowired
	private E baseDao;
	
	@Override
	public int deleteById(Serializable id) {
		
		int flag = baseDao.deleteById(id);
		
		return flag;
	}

	@Override
	public int insert(T record) {
		
		int flag = baseDao.insert(record);
		
		return flag;
	}

	@Override
	public R queryById(Serializable id) {
		
		R r = baseDao.queryById(id);
		return r;
	}

	@Override
	public R query(T record) {
		
		R r = baseDao.query(record);
		return r;
	}

	@Override
	public List<R> list(T record) {
		return baseDao.list(record);
	}

	@Override
	public int update(T record) {
		
		int flag = baseDao.update(record);
		
		
		return flag;
	}

	@Override
	public PageListVo<R> page(T record, PageListVo<R> page) {
		
        PageListVo<R> list = null;
 
        PageBounds pageBounds = new PageBounds(page.getCurrPage(), page.getPageSize());
        PageList<R> pageList = baseDao.page(record, pageBounds);
        list = new PageListVo<R>(pageList.getPaginator().getTotalCount(), pageList, page.getCurrPage(), page.getPageSize());

        return list;
	}

	@Override
	public int delete(T record) {
		return baseDao.delete(record);
	}

	@Override
	public Long count(T record) {
		return baseDao.count(record);
	}
	
	

}
